package com.woniuxy.microretailserver.mapper;

import com.woniuxy.microretailserver.bean.OrderGoodsBean;
import com.woniuxy.microretailserver.bean.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author chenhu
 * 购买商品持久层接口
 */
@Mapper
@Repository
public interface OrderGoodsMapper {

    /**
     * 新增购买商品
     *
     * @param orderGoodsBean
     * @return
     */
    @Insert("insert into t_ordergoods_info" +
            "(goods_name,goods_price,goods_num,goods_rule,goods_status,fk_order_id)" +
            " values(#{o.goodsName},#{o.goodsPrice},#{o.goodsNum},#{o.goodsRule},#{o.goodsStatus},#{o.goodsOrderBean.id})")
    int saveOrderGoods(@Param("o") OrderGoodsBean orderGoodsBean);

    /**
     * 新增退货商品
     * @param orderGoodsBean
     * @return
     */
    @Insert("insert into t_ordergoods_info" +
            "(goods_name,goods_price,goods_num,goods_rule,goods_status,fk_return_id)" +
            " values(#{o.goodsName},#{o.goodsPrice},#{o.goodsNum},#{o.goodsRule},#{o.goodsStatus},#{o.goodsReturnInfoBean.id})")
    int saveOrderReturnGoods(@Param("o") OrderGoodsBean orderGoodsBean);

    /**
     * 根据购买订单id查询购买商品信息
     * @param id
     * @return
     */
    @Select("select * from t_ordergoods_info as o where o.fk_order_id=#{id}")
    List<OrderGoodsBean> findByIdOrder(@Param("id") long id);

    /**
     * 根据购买订单id查询退货商品信息
     * @param id
     * @return
     */
    @Select("select * from t_ordergoods_info as o where o.fk_return_id=#{id}")
    List<OrderGoodsBean> findByIdReturnOrder(@Param("id") long id);

    /**
     * 分页查询商品与订单信息
     * @param request
     * @param orderGoodsBean
     * @return
     */
    List<OrderGoodsBean> findPageOrder(@Param("p")PageRequest request,@Param("o") OrderGoodsBean orderGoodsBean);
}
